import Vue from 'vue'
import Vuex from 'vuex'
import { http } from '../http'
import { mutations } from './mutations'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    todoLists: JSON.parse(localStorage.getItem('todoLists')) || [],
    finisheAjax: false
  },
  mutations: mutations,
  actions: {
    getLists(context) {
      context.commit('CHANGESTATUS', false)
      http('todos.json', 'GET')
      .then(res => {
        context.commit('_REPLACE', res)
        context.commit('CHANGESTATUS', true)
      })
    }
  },
  modules: {
  }
})
